/*
 * Copyright (C) 2019 Fastjrun, Inc. All Rights Reserved.
 */
package com.fastjrun.demo.mock;

import static org.powermock.api.mockito.PowerMockito.when;

import org.powermock.api.mockito.PowerMockito;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.fastjrun.demo.bean.User;

@Configuration
public class UtilMockFactory {
    @Bean
    public RedisTemplate<String, User> getRedisTemplate() {
        RedisTemplate<String, User> redisTemplate =
                (RedisTemplate<String, User>) PowerMockito.mock(RedisTemplate.class);
        when(redisTemplate.hasKey("myLogin_autoUt_4uuid")).thenReturn(true);
        ValueOperations valueOperations = PowerMockito.mock(ValueOperations.class);
        when(valueOperations.get("myLogin_autoUt_4uuid")).thenReturn(new User());
        when(redisTemplate.opsForValue()).thenReturn(valueOperations);
        return redisTemplate;

    }
}
